<?php


	/**
	 * this is a class for building sitemaps.. it should eventually have some sort of dom type access methods..
	 * but not just now.
	 * 
	 * takes an array which represents the site in tree form
	 * 
	 * this is perhaps not the best way to engineer things.. 
	 * $node['link']
	 * $node['title']
	 * $node['description']
	 * $node['children']
	 * google adds additional things which we may find useful.
	 * $node['priority']  - this is a weighting of how important you think the content is.. 
	 * $node['lastmod']  - when the content last changed
	 * $node['changefreq'] - how often the content changes.. please dont lie here.. needs to be sensible..
	 */
	
//	define("CMS_SITE_MAP_GOOGLE",'CmsSiteMapGoogle');
//	define("CMS_SITE_MAP_HTML",'CmsSiteMapHTML');
	
	class FTASiteMap {
		
		var $root;
		
		function CmsSiteMap(&$root){
			$this->root = &$root;			
		}
		
		function setRoot(&$root){
			$this->root = &$root;
		}
		
		function generateNode($node){
			//do nothing other than recurse..
			$ret = "";
			if (key_exists('children',$node) &&  is_array($node['children']) && 0 < count($node['children']) ){
					$ret .= $this->rGenerateSiteMap($node['children']);
			}
			return $ret;
		}
		
		function generateSiteMap(){
			if (is_array($this->root) && 0 < count($this->root))
				return $this->rGenerateSiteMap($this->root);
			else 
				return null;
		}
		
		function rGenerateSiteMap($nodeSet) {
			$ret ="";
			foreach ($nodeSet as $node){
				$ret .= $this->generateNode($node);
			}
			return $ret;
		}
		
	}
		

	
	/**
	 * Gets the fta obejct.. these are singletons really..
	 *
	 * @return FTAWebPage
	 */
	function fta_getSharedSiteMapObject(){

		global $fta_;
		global $FTASiteMapClass;
		
		if(!is_null($FTASiteMapClass) && "FTASiteMap" != $FTASiteMapClass){
		} else {
			$FTASiteMapClass = "FTASiteMap";
		}
			
		if (!array_key_exists('ftaSiteMap',$fta_)){
			$fta_->ftaSiteMap = new  $FTASiteMapClass();
		}
		return $fta_->ftaSiteMap;
	}
	
	